package cn.ailanyin.home.module.user.controller;

import cn.ailanyin.home.common.entity.Result;
import cn.ailanyin.home.module.user.dto.UserDTO;
import cn.ailanyin.home.module.user.entity.User;
import cn.ailanyin.home.module.user.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 小怪兽
 * @version 1.0
 * @date 2024/4/13 0013 19:34:53
 */
@Validated
@RestController
@RequiredArgsConstructor
@Tag(name = "用户管理")
@RequestMapping("/user")
public class UserController {

    /**
     * 用户服务
     */
    private final UserService userService;


    /**
     * 获取用户信息
     *
     * @return {@link Result}<{@link User}>
     */
    @GetMapping("/getUserInfo")
    @Operation(summary = "获取用户信息")
    public Result<User> getUserInfo(){
        return Result.success(userService.getUser());
    }

    /**
     * 更新用户信息
     *
     * @param dto dto
     * @return {@link Result}<{@link User}>
     */
    @PostMapping
    @Operation(summary = "修改用户信息")
    public Result<User> updateUserInfo(@RequestBody UserDTO dto){
        userService.updateUserInfo(dto);
        return Result.success();
    }

}
